import pandas as pd
import numpy as np
 
def read_excel_row_by_row(file_path):
    df = pd.read_excel(file_path)
    for index, row in df.iterrows():
        yield row
 
# 使用生成器读取 Excel
file_path = 'example.xlsx'    
# 打开文件用于写入，如果文件不存在将会被创建
with open('example.txt', 'w') as file:

    file.write("Reg\n")
    file.write("{\n")
    for row in read_excel_row_by_row(file_path):
        file.write("Point_t ")
        file.write(row[0])# 将文本写入文件
        file.write(";")
        file.write("\n")
        # print(row[0])
    file.write("}")
    file.write("\n")

    file.write("Init\n")
    file.write("{\n")
    for row in read_excel_row_by_row(file_path):

        file.write(row[0])# 将文本写入文件
        file.write(".")
        file.write("x=")
        file.write(str(row[1]))
        file.write(";")
        file.write("\n")

        file.write(row[0])# 将文本写入文件
        file.write(".")
        file.write("y=")
        file.write(str(row[2]))
        file.write(";")
        file.write("\n")

        file.write(row[0])# 将文本写入文件
        file.write(".")
        file.write("z=")
        file.write(str(row[3]))
        file.write(";")
        file.write("\n")

        file.write(row[0])# 将文本写入文件
        file.write(".")
        file.write("code=")
        file.write(str(row[4]))
        file.write(";")
        file.write("\n")

        file.write("\n")
    file.write("}")
    file.write("\n")


    file.write("Point_enum\n")
    file.write("{\n")
    for row in read_excel_row_by_row(file_path):
        file.write("Action_")
        file.write(row[0])# 将文本写入文件
        file.write(",")
        file.write("\n")
        # print(row[0])
    file.write("}")
    file.write("\n")

    file.write("switch(FollowManager.ActionList)\n")
    file.write("{\n")

    for row in read_excel_row_by_row(file_path):
        file.write("case ")
        file.write("Action_")
        file.write(row[0])# 将文本写入文件
        file.write(":\n")
        file.write("{\n")
        file.write("Go_Position(")
        file.write(row[0])
        file.write(");")
        file.write("\n")
        file.write("ActionHoldChange(800,")
        file.write("Action_")
        file.write(row[5])
        file.write(");\n")
        file.write("break;\n")
        # print(row[0])
        file.write("}")
        file.write("\n")

        
    file.write("}")


